package com.zhoufeng.common;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Locale;
import java.util.Properties;

public class Common {
	public static final int COMMAND_LENGTH = 22 ;
	public static final int UDP_APP_PORT = 5005;
	public static final int UDP_DEVICE_PORT = 5000;

	public static final String bytesToHexString(byte data) {
		String tempStr = "";
		tempStr = Integer.toHexString(0xFF & data).toUpperCase(Locale.getDefault());

		if (tempStr.length() < 2) {
			tempStr = "0" + tempStr;
		}
		return tempStr;
	}

	public static Properties loadPropertyFile(String file) {
		InputStream inputStream = null;
		Properties properties = null;
		try {
			inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(file); // properties.load(Prop.class.getResourceAsStream(fileName));
			if (inputStream == null)
				throw new IllegalArgumentException("Properties file not found in classpath: " + file);
			properties = new Properties();
			properties.load(new InputStreamReader(inputStream));
		} catch (IOException e) {
			throw new RuntimeException("Error loading properties file.", e);
		} finally {
			if (inputStream != null)
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}

		return properties;
	}

}
